package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.mapper.LogMapper;
import com.jt.pojo.Bill;
import com.jt.pojo.Customer;
import com.jt.pojo.Log;
import com.jt.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class LogServciceImpl implements LogService{
    @Autowired
    public LogMapper logMapper;

//    @Async
//    @Override
//    public void insertLog(Log log) {
//        logMapper.insert(log);
//    }



    @Override
    public PageResult getlogList(PageResult pageResult) {
        boolean flag = StringUtils.hasLength(pageResult.getQuery());
        QueryWrapper<Log> queryWrapper =new QueryWrapper<>();
        queryWrapper.like(flag,"name",pageResult.getQuery());
        //编辑mp的分页对象 四个属性有用(页数/条数/总数/记录) 传递= 页面/条数
        IPage<Log> page = new Page<>(pageResult.getPageNum(),pageResult.getPageSize());
        page = logMapper.selectPage(page, queryWrapper);
        //获取总数
        long total = page.getTotal();
        //获取记录数
        List<Log> rows = page.getRecords();
        //将数据封装
        return pageResult.setTotal(total).setRows(rows);
    }
    @Async
    @Override
    public void insertLog(Log logInfo) {
        logMapper.insert(logInfo);
    }

    @Override
    public void deletelogId(Integer id) {
        logMapper.deleteById(id);
    }


}
